package com.zzyl.controller.manager;

import cn.hutool.core.lang.UUID;
import com.sun.xml.bind.v2.TODO;
import com.zzyl.base.ResponseResult;
import com.zzyl.entity.NursingProject;
import com.zzyl.file.FileStorageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

@Slf4j
@RestController
@RequestMapping("/common")
@Api(tags = "通用接口")
public class CommonController {
    @Autowired
    FileStorageService fileStorageService;

    @ApiOperation("文件上传")
  /*  @PostMapping("/upload")
    public ResponseResult<String> file(MultipartFile file) throws IOException {
        String store = fileStorageService.upload(file);
        return ResponseResult.success(store);
    }*/
    @PostMapping("/upload")
    public ResponseResult<String> file(MultipartFile file) throws IOException {
        //String objectName = file.getOriginalFilename();
        InputStream inputStream = file.getInputStream();
        String store = fileStorageService.store(UUID.randomUUID().toString(), inputStream);
        return ResponseResult.success(store);
    }
}
